﻿//JumbotCms_4.1 Final
using System;
using System.Web;
using System.Data;
using Jumbot.Common;
using JumbotCms.Common;
namespace JumbotCms.WebFile.User
{
    public partial class _noticeajax : JumbotCms.API.UserCenter
    {
        private string _operType = string.Empty;
        private string _response = string.Empty;

        protected void Page_Load(object sender, EventArgs e)

        {
            if (!CheckFormUrl())
            {
                Response.Write("提交有误");
                Response.End();
            }

            this._operType = q("oper");
            switch (this._operType)
            {
                case "check":
                    ajaxCheck();
                    break;
                case "ajaxDel":
                    ajaxDel();
                    break;
                case "newlist":
                    ajaxNewList();
                    break;
                case "ajaxGetList":
                    ajaxGetList();
                    break;
                default:
                    DefaultResponse();
                    break;
            }
            Response.Write(this._response);
        }
        private void DefaultResponse()
        {
            User_Load("", "json");
        }
        private void ajaxNewList()
        {
            User_Load("", "json");
            doh.Reset();
            doh.ConditionExpress = "UserId=" + UserId + " and state=0";
            int _count = doh.Count("jcms_normal_user_notice");
            if (_count > 0)
                this._response = JsonResult(1, "" + _count);
            else
                this._response = JsonResult(0, "0");
        }
        private void ajaxGetList()
        {
            User_Load("", "json");
            int page = Int_ThisPage();
            int PSize = Str2Int(q("pagesize"), 10);
            int countNum = 0;
            string sqlStr = "";
            string whereStr = "UserId=" + UserId;
            string type = q("type");
            if (type != "")
            {
                whereStr += " AND [NoticeType]='" + type + "'";
            }
            doh.Reset();
            doh.ConditionExpress = whereStr;
            countNum = doh.Count("jcms_normal_user_notice");
            doh.Reset();
            doh.ConditionExpress = "id in(" + Jumbot.Common.staticFunction.GetSql("Id", "jcms_normal_user_notice", "Id", PSize, page, "desc", whereStr) + ")";
            doh.AddFieldItem("State", 1);
            doh.Update("jcms_normal_user_notice");
            sqlStr = Jumbot.Common.staticFunction.GetSql("Id,Title,Content,AddDate,State", "jcms_normal_user_notice", "Id", PSize, page, "desc", whereStr);
            doh.Reset();
            doh.SqlCmd = sqlStr;
            DataTable dt = doh.GetDataTable();
            this._response = "{result :\"1\"," +
                "returnval :\"操作成功\"," +
                "pagerbar :\"" + Jumbot.Common.HtmlPager.GetPageBar(3, "js", 2, countNum, PSize, page, "javascript:ajaxList(<#page#>);") + "\"," +
                Jumbot.Common.JsonHelp.DtToSON(dt, (PSize * (page - 1))) +
                "}";
            dt.Clear();
            dt.Dispose();
        }
        private void ajaxCheck()
        {
            User_Load("", "json");
            string nId = f("id");
            doh.Reset();
            doh.ConditionExpress = "id=@id and UserId=" + UserId;
            doh.AddConditionParameter("@id", nId);
            doh.AddFieldItem("State", 1);
            if (doh.Update("jcms_normal_user_notice") != 0)
                this._response = JsonResult(1, "标识已读成功");
            else
                this._response = JsonResult(0, "参数有误");
        }
        private void ajaxDel()
        {
            User_Load("", "json");
            string nId = f("id");
            doh.Reset();
            doh.ConditionExpress = "id=@id and UserId=" + UserId;
            doh.AddConditionParameter("@id", nId);
            if (doh.Delete("jcms_normal_user_notice") != 0)
                this._response = JsonResult(1, "删除成功");
            else
                this._response = JsonResult(0, "删除失败");
        }
    }
}
